package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.api.TeachplanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;

import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService  teachplanService;


    @GetMapping("teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTreenodesByCourseId(@PathVariable Long courseBaseId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        return teachplanService.queryTreenodesByCourseId(courseBaseId,companyId);
    }

    @PostMapping("/teachplan")
    public TeachplanDTO createOrModifyTeachplan(@RequestBody TeachplanVO vo) {
        Long companyId = UAASecurityUtil.getCompanyId();

        TeachplanDTO dto=TeachplanConvert.INSTANCE.vo2dto(vo);

        return teachplanService.createOrModifyTeachplan(dto,companyId);
    }

    @DeleteMapping("/teachplan/{teachPlanId}")
    public void removeTeachplan(@PathVariable String teachPlanId) {
        Long companyId = UAASecurityUtil.getCompanyId();


        teachplanService.removeTeachplan(teachPlanId,companyId);
    }


}
